#include <sdfs/storage/StorageServer.h>
#include <sdfs/storage/ConfigServer.h>
#include <sdfs/config/StorageConfig.h>
#include <stdio.h>
#include <muduo/base/Logging.h>
#include <muduo/base/LogFile.h>

using namespace muduo;
using namespace sdfs::storage;

boost::scoped_ptr<muduo::LogFile> g_logFile;

void logOutput(const char* msg, int len)
{
	g_logFile->append(msg, len);
}

int main(int argc, char* argv[])
{
//	g_logFile.reset(new muduo::LogFile("storage",500*1000*1000, true));
//	muduo::Logger::setOutput(logOutput);
	if(argc > 1)
		sdfs::StorageConfig::setConfigFilename(argv[1]);
	else
		sdfs::StorageConfig::setConfigFilename("storage.conf");
	sdfs::StorageConfig& conf = sdfs::StorageConfig::getInstance();
	LOG_INFO << "PID = "<< getpid() << ", tid = "<< CurrentThread::tid();
	int numThreads = conf.threadNum();
	EventLoop loop;
	InetAddress listenAddr(conf.filePort());
	InetAddress confAddr(conf.configPort());
	InetAddress trackerAddr = conf.trackers()->at(0);
	StorageServer server(&loop, listenAddr, trackerAddr, numThreads);
	ConfigServer confSever(&loop, confAddr);
	
	server.start();
	confSever.start();
	loop.loop();
	
}
